package models

import (
	"fmt"
)

type Book struct {
	ID uint 	`json:"id"`
	Name string `json:"name"`
	Path string `json:"path"`
	CatId uint `json:"cat_id"`
	Size uint 
	SizeU string `json:"size"`
}



func (Book) TableName() string {
	return "book"
}

func (book *Book) SetSize() {
	types := [5]string{"B", "KB", "MB", "GB", "TB"}
	step, i := 1024.0, 0
	size := float64(book.Size)
	for size > step {
		size = size / step
		i++
	}
	book.SizeU = fmt.Sprintf("%.2f%v", size, types[i])


}

type Filter struct {
	Offset int `json:"offset"`
	Count int `json:"count"`
	Keyword string `json:"keyword"`
}